package menuService

import (
	"gitee.com/yangguoliang001/go-gin-vue3/QO"
	"gitee.com/yangguoliang001/go-gin-vue3/dao/menuActionDao"
	"gitee.com/yangguoliang001/go-gin-vue3/dao/menuDao"
	"gitee.com/yangguoliang001/go-gin-vue3/vo"
	"github.com/gin-gonic/gin"
	"github.com/go-redis/redis/v7"
	"gorm.io/gorm"

	"go.uber.org/zap"
)

type MenuServices interface {
	QueryMenuList(c *gin.Context) (menuList []vo.MenuItemVO, err error)
	QueryMenuItemDetail(c *gin.Context, id string) (menuItem vo.MenuItemVO, err error)
	EditMenu(c *gin.Context, editReq QO.EditReq) (err error)
	UpdateMenuUsed(c *gin.Context, usedReq QO.MenuUsedReq) (err error)
	UpdateMenuSort(c *gin.Context, sortReq QO.MenuSortReq) (err error)
	DeleteMenu(c *gin.Context, id int32) (err error)
	QueryMenuActionList(c *gin.Context, id string) (res vo.MenuActionVO, err error)
	AddMenuAction(c *gin.Context, req QO.AddMenuActionReq) (err error)
	DeleteMenuAction(c *gin.Context, id string) (err error)
}

type menuService struct {
	logger        *zap.Logger
	cache         *redis.Client
	menuDao       menuDao.MenuDao
	menuActionDao *menuActionDao.MenuActionDao
}

func New(logger *zap.Logger, db *gorm.DB, cache *redis.Client) MenuServices {
	return &menuService{
		logger:        logger,
		cache:         cache,
		menuDao:       menuDao.New(db),
		menuActionDao: menuActionDao.New(db),
	}
}
